#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2021/4/25 7:59 下午
# @Author : sxt
# @Version：V 1.0
# @File : views_admin.py
# @desc : 后台管理接口
from rest_framework.decorators import action

from app.models import User, DbCourseType
from app.serializers import UserSerializer, CourseTypeSerializer
from threedGestureProject.authandpermissions.permissions import SuperUserPermission
from threedGestureProject.common.result import BaseResponse
from threedGestureProject.common.viewset import TokenViewSet
from app.views import UserApi as _UserApi


class UserApi(TokenViewSet):
    """
    用户管理
    """
    queryset = User.objects.all()
    serializer_class = UserSerializer
    permission_classes = [SuperUserPermission, ]

    @action(methods=['POST'], url_path='login', detail=False, permission_classes=[])
    def admin_login(self, request):
        return _UserApi.real_login(self.queryset, request)


class CourseTypeApi(TokenViewSet):
    """
    课程类型管理
    """
    queryset = DbCourseType.objects.all()
    serializer_class = CourseTypeSerializer
    permission_classes = [SuperUserPermission, ]
